package com.millstein.tsinglog.controller;

import com.millstein.tsinglog.annotation.ResponseResult;
import com.millstein.tsinglog.commons.constant.SystemConstant;
import com.millstein.tsinglog.service.UploadService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/upload")
@ResponseResult
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 上传图片
     * @param file 上传的文件名称
     * @return
     */
    @PostMapping("/uploadImage")
    @CrossOrigin(origins = SystemConstant.PATH_MANAGER, allowCredentials = "true")
    @RequiresPermissions(value= {"article:insert", "article :update", "carousel:insert", "carousel:update"},
            logical = Logical.OR)
    public Map<String, Object> uploadImage (MultipartFile file) {
        return uploadService.uploadImage(file);
    }
}
